home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / T_BCINFO.ARJ / TI730.ASC < prev    next >
Text File  |  1992-02-25  |  14KB  |  463 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  730
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/7
  12.  
  13.     TITLE  :  Example Source Code for TEMC Filter
  14.  
  15.  
  16.  
  17.  
  18.   /*
  19.        EXAMPLE SOURCE CODE FOR TEMC FILTER
  20.  
  21.        TEMC2MSG.C
  22.  
  23.        TEMC2Msg - output filter to Turbo C++ IDE message window
  24.             This filter accepts input through the standard input
  25.             stream, converts it and outputs it to the standard
  26.             output stream.  The streams are linked through pipes,
  27.             such that the input stream is the output from the
  28.             assembler being invoked, and the output stream is
  29.             connected to the message window of the Turbo C++ IDE,
  30.             ie. temc fname configname | temc2msg | Turbo C++
  31.             message window
  32.  
  33.        Compile using Turbo C++ in the LARGE memory model
  34.             tcc -ml temc2msg
  35.   */
  36.  
  37.   #include <dir.h>
  38.   #include <dos.h>
  39.   #include <stdlib.h>
  40.   #include <fcntl.h>
  41.   #include <string.h>
  42.   #include <alloc.h>
  43.   #include <io.h>
  44.   #include <ctype.h>
  45.   #include "filter.h"
  46.  
  47.   #define TRUE (1 == 1)
  48.   #define FALSE !(TRUE)
  49.  
  50.   /* Turbo TEMC text for conversion */
  51.   char TemcWarningTxt[] = "Warning ";
  52.   char TemcErrorTxt[]   = "Error ";
  53.   char TemcFatalTxt[]   = "Fatal ";
  54.  
  55.   char     CurFile[MAXPATH];       /* Current file in message
  56.   window */
  57.   unsigned BufSize,                /* Size of internal working
  58.   buffer */
  59.            CurBufLen;              /* Buffer space in use */
  60.   char     *InBuffer,              /* Input buffer */
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  730
  75.   VERSION  :  2.0
  76.        OS  :  DOS
  77.      DATE  :  February 25, 1992                        PAGE  :  2/7
  78.  
  79.     TITLE  :  Example Source Code for TEMC Filter
  80.  
  81.  
  82.  
  83.  
  84.            *OutBuffer,             /* Output buffer */
  85.            *CurInPtr,              /* current character in input
  86.                                       buffer */
  87.            *CurOutPtr,             /* current character in output*/
  88.            *LinePtr;               /* pointer to the current
  89.                                       character in the input
  90.                                       buffer*/
  91.   int      (*processor)(char *);   /* function pointer used to call
  92.                                       the appropriate conversion
  93.                                       routine */
  94.   char     Line[133];              /* static buffer to store line
  95.                                       most recently input */
  96.   long int InOff;                  /* position in actual input
  97.                                       stream */
  98.   char     EndMark;                /* Used to output end of data to
  99.   message
  100.                                       window */
  101.  
  102.   /*************************************************************************
  103.   Function  : NextChar
  104.   Parameters: none
  105.   Returns   : next character in input buffer or 0 on end of file
  106.  
  107.   Input from the standard input stream is buffered in a global
  108.   buffer InBuffer which is allocated in function main.  The
  109.   function will return the next character in the buffer, reading
  110.   from the input stream when the buffer becomes empty.
  111.   **********************************************************************/
  112.   char NextChar(void)
  113.   {
  114.     if (CurInPtr < InBuffer+CurBufLen)  /* if buffer is not empty*/
  115.     {
  116.       return *(CurInPtr++);             /* return next character */
  117.     }
  118.     else
  119.     {
  120.       CurInPtr = InBuffer;              /* reset pointer to front
  121.                                            of buffer */
  122.       lseek(0,InOff,0);                 /* seek to the next section
  123.                                            for read */
  124.       InOff += BufSize;                 /* increment pointer to
  125.                                            next block */
  126.       if ((CurBufLen = read(0,InBuffer,BufSize)) !=0)
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                            NUMBER  :  730
  141.   VERSION  :  2.0
  142.        OS  :  DOS
  143.      DATE  :  February 25, 1992                        PAGE  :  3/7
  144.  
  145.     TITLE  :  Example Source Code for TEMC Filter
  146.  
  147.  
  148.  
  149.  
  150.         return NextChar();              /* recursive call merely
  151.                                            returns first character
  152.                                            in buffer after read */
  153.       return 0;                         /* return 0 on end of
  154.                                            file*/
  155.     }
  156.   }
  157.  
  158.   /*************************************************************************
  159.   Function  : flushOut
  160.   Parameter : Size   The number of characters to be written out
  161.   Returns   : nothing
  162.  
  163.   Strings to be sent to the message window are buffered in a buffer
  164.   called OutBuffer.  A call to this function will write out Size
  165.   bytes from OutBuffer to the standard output stream and resets the
  166.   output buffer pointer to the beginning of the buffer.  The output
  167.   buffer is considered empty after a call to this function.
  168.   ***********************************************************************/
  169.   void flushOut(unsigned Size)
  170.   {
  171.      if (Size != 0)                /* don't flush an empty buffer*/
  172.      {
  173.         CurOutPtr = OutBuffer;     /* reset pointer to beginning of
  174.                                       buffer */
  175.         lseek(1,0,2);              /* seek output stream to end */
  176.         write(1,OutBuffer,Size);   /* write out Size bytes */
  177.      }
  178.   }
  179.  
  180.   /************************************************************************
  181.   Function  : Put
  182.   Parameters: S    pointer to bytes being put into output buffer
  183.               Len  number of bytes to be put in output buffer
  184.   Returns   : nothing
  185.  
  186.   Put places bytes into OutBuffer so they may be later flushed out
  187.   into the standard output stream.
  188.   ***********************************************************************/
  189.   void Put(char *S,int Len)
  190.   {
  191.      int i;
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                            NUMBER  :  730
  207.   VERSION  :  2.0
  208.        OS  :  DOS
  209.      DATE  :  February 25, 1992                        PAGE  :  4/7
  210.  
  211.     TITLE  :  Example Source Code for TEMC Filter
  212.  
  213.  
  214.  
  215.  
  216.      for (i = 0; i < Len; i++)
  217.      {
  218.         *CurOutPtr++ = S[i];             /* place byte in buffer */
  219.         if (CurOutPtr >= OutBuffer+BufSize)/* if buffer overflows*/
  220.            flushOut(BufSize);               /* flush the buffer */
  221.      }
  222.   }
  223.  
  224.   /*************************************************************************
  225.   Function  : ProcessLine
  226.   Parameters: Line  a pointer to the current line of characters to
  227.                     process
  228.   Returns   : 1 if line is a Turbo Assembler line
  229.               0 if line is not
  230.  
  231.   Process through a line of input to determine if it is a Turbo
  232.   Assembler output line and convert it to information for the Turbo
  233.   C++ message window.
  234.  
  235.   Turbo Assembler lines which are in need of conversion are of the
  236.   form:
  237.  
  238.       message-type source-file(LINE #) message-text
  239.  
  240.   where type is one of: Warning, Error
  241.  
  242.   TASM lines are identified by the first portion of text.  If
  243.   warning, error or fatal is determined at the outset, text is
  244.   output from there as it is scanned.  Any incorrect configuration
  245.   will simply abort the scanning of the rest of the line.
  246.   **********************************************************************/
  247.   int ProcessLine(char *Line)
  248.   {
  249.      char     Type;
  250.      unsigned i;
  251.      char     *s;
  252.        char     fn[MAXPATH];
  253.  
  254.      /* don't try to process a NULL line */
  255.      if (Line[0] == 0)
  256.         return 0;
  257.  
  258.      /* check for temc type tags */
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                            NUMBER  :  730
  273.   VERSION  :  2.0
  274.        OS  :  DOS
  275.      DATE  :  February 25, 1992                        PAGE  :  5/7
  276.  
  277.     TITLE  :  Example Source Code for TEMC Filter
  278.  
  279.  
  280.  
  281.  
  282.      if (strncmp(Line,TemcWarningTxt,strlen(TemcWarningTxt))== 0)
  283.         memmove(Line,&Line[strlen(TemcWarningTxt)],strlen(Line));
  284.      else if (strncmp(Line,TemcErrorTxt,strlen(TemcErrorTxt))== 0)
  285.         memmove(Line,&Line[strlen(TemcErrorTxt)],strlen(Line));
  286.      else if (strncmp(Line,TemcFatalTxt,strlen(TemcFatalTxt))== 0)
  287.         memmove(Line,&Line[strlen(TemcFatalTxt)],strlen(Line));
  288.      else return 1;             /* geen TEMC line */
  289.  
  290.       s = strchr(Line,':');        /* find : */
  291.       if (s != NULL)               /* if no :, invalid line */
  292.           {
  293.           while (*s != ' ')
  294.             s--;
  295.           memmove(fn,Line,(unsigned)(s-Line)); /*save filename*/
  296.           fn[(unsigned)(s-Line)] = 0;  /* null terminate name */
  297.           memmove(Line,++s,strlen(Line));  /* shift line left */
  298.           if (strcmp(fn,CurFile) != 0)   /* if new filename */
  299.                {
  300.                Type = MsgNewFile; /* indicate by sending type
  301.                                      out to message window */
  302.             strcpy(CurFile,fn);
  303.             Put(&Type,1);
  304.             Put(CurFile,strlen(CurFile)+1);                 /*
  305.   along with the new name */
  306.             }
  307.              Type = MsgNewLine;   /* set type to new line */
  308.           s = strchr(Line,':');     /* find : */
  309.           *s = 0;           /* isolate number in string */
  310.           i = atoi(Line); /* if number is found convert string
  311.                                 to integer */
  312.              if (i != 0)
  313.             {
  314.             Put(&Type,1);    /* indicate need for new line */
  315.             Put((char *)&i,2);     /* put the number out */
  316.             i = 1;           /* set column in message box */
  317.             Put((char *)&i,2);  /* tab over to put message */
  318.             s++;
  319.             memmove(Line,s,strlen(s)+1);    /* shift line */
  320.             while (Line[0] == ' ' && Line[0] != 0)  /* strip
  321.                                                spaces from line */
  322.                 memmove(Line,&Line[1],strlen(Line));
  323.             Put(Line,strlen(Line)+1); /*output the message */
  324.             return 0;              /* OK Temc line */
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                            NUMBER  :  730
  339.   VERSION  :  2.0
  340.        OS  :  DOS
  341.      DATE  :  February 25, 1992                        PAGE  :  6/7
  342.  
  343.     TITLE  :  Example Source Code for TEMC Filter
  344.  
  345.  
  346.  
  347.  
  348.             }
  349.            return 1;   /* invalid line number, not TASM line */
  350.            }
  351.            else        /* Fatal error, no line # or filename */
  352.             {
  353.             Type = MsgNewLine; /* Fake line #  etc.*/
  354.             i = 1;
  355.             Put(&Type,1);
  356.             Put((char *)&i,2);
  357.             Put((char *)&i,2);
  358.             while (Line[0] == ' ' && Line[0] != 0)
  359.                  memmove(Line,&Line[1],strlen(Line));
  360.             Put(Line,strlen(Line)+1);
  361.             return 0;
  362.             }
  363.   }
  364.  
  365.   /***********************************************************************
  366.   Function  : main
  367.  
  368.   Returns   : zero for successful execution
  369.               3    if an error is encountered
  370.  
  371.   The main routine allocates buffers for the input and output
  372.   buffer.  Characters are then read from the input buffer building
  373.   the line buffer that will be sent to the filter processor.  Lines
  374.   are read and filtered until the end of input is reached.
  375.   ***********************************************************************/
  376.   int main( void )
  377.   {
  378.      char c;
  379.      unsigned long core;
  380.  
  381.      setmode(1,O_BINARY);    /* set output stream to binary mode */
  382.      core = farcoreleft();
  383.      if (core > 64000U)
  384.         BufSize = 64000U;
  385.      else BufSize = (unsigned)core;     /* get available memory */
  386.                                         /* stay under 64K */
  387.      if ((CurInPtr = malloc(BufSize)) == NULL) /* allocate buffer
  388.                                                   space */
  389.         exit(3);
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.   PRODUCT  :  Borland C++                            NUMBER  :  730
  405.   VERSION  :  2.0
  406.        OS  :  DOS
  407.      DATE  :  February 25, 1992                        PAGE  :  7/7
  408.  
  409.     TITLE  :  Example Source Code for TEMC Filter
  410.  
  411.  
  412.  
  413.  
  414.      processor = NULL;                  /* set current processor to
  415.                                            none */
  416.      InBuffer = CurInPtr;               /* input buffer is first
  417.                                            half of space */
  418.      BufSize = BufSize/2;               /* output buffer is 2nd
  419.                                            half */
  420.      OutBuffer = InBuffer + BufSize;
  421.      CurOutPtr = OutBuffer;             /* set buffer pointers */
  422.      LinePtr = Line;
  423.      CurBufLen = 0;
  424.      Put(PipeId,PipeIdLen);             /* send ID string to
  425.                                            message window */
  426.      while ((c = NextChar()) != 0)      /* read characters */
  427.      {
  428.         if ((c == 13) || (c == 10))     /* build until line end */
  429.         {
  430.            *LinePtr = 0;
  431.            ProcessLine(Line);           /* filter the line */
  432.            LinePtr = Line;
  433.         }
  434.       /* characters are added to buffer up to 132 characters max */
  435.         else if ((FP_OFF(LinePtr) - FP_OFF(&Line)) < 132)
  436.         {
  437.            *LinePtr = c;                /* add to line buffer */
  438.            LinePtr++;
  439.         }
  440.      }
  441.      *LinePtr = 0;
  442.      ProcessLine(Line);                 /* filter last line */
  443.      EndMark = MsgEoFile;
  444.      Put(&EndMark,1);                   /* indicate end of input to
  445.                                            the message window */
  446.      flushOut((unsigned)(CurOutPtr-OutBuffer)); /*flush the
  447.                                                   buffer*/
  448.      return 0;                          /* return OK */
  449.   }
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.